/** 数据操作对象 */
import {
  GOODS_ADD,
  GOODS_DEL,
  GOODS_EDIT,
  GOODS_ALL,
  GOODS_INIT
} from './goodsType'

import {
  findAll
} from "../../api/goodsApi"

// 1.请求由react组件发送
// export const goodsInitAction = data => ({ type: GOODS_INIT, data })
// 2.请求由store reducer函数发送
// export const goodsInitAction = () => ({ type: GOODS_INIT, data: '' })
// 3.请求由store creator发送
export const goodsInitAction = () => {
  // 封装API函数的调用
  return async dispatch => {
    // 发送异步请求
    let response = await findAll()
    // 交给reducer同步数据
    dispatch({ type: GOODS_INIT, data: response.data })
  }
}
export const goodsAddAction = data => ({ type: GOODS_ADD, data })
export const goodsDelAction = data => ({ type: GOODS_DEL, data })
export const goodsEditAction = data => ({ type: GOODS_EDIT, data })
export const goodsAllAction = data => ({ type: GOODS_ALL, data })